# 递归

class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        if not root:
            return []
        ans = [root.val]
        for i in range(len(root.children)):
            ans.extend(self.preorder(root.children[i]))
        return ans

#  迭代参照官方解答